package com.yn.front.controller;

import com.yn.common.constants.CategoryConstants;
import com.yn.common.page.BasePage;
import com.yn.common.response.sc.ArticleResponse;
import com.yn.common.response.sc.BaseResult;
import com.yn.common.request.sc.PageParamRequest;
import com.yn.common.model.article.Article;
import com.yn.common.model.category.Category;
import com.yn.service.service.ArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 文章
 *
 */
@Slf4j
@RestController("ArticleFrontController")
@RequestMapping("api/front/article")
@Api(tags = "文章")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    /**
     * 分页列表
     */
    @ApiOperation(value = "分页列表")
    @RequestMapping(value = "/list/{cid}", method = RequestMethod.GET)
    public BaseResult<BasePage<ArticleResponse>> getList(@PathVariable(name="cid") String cid,
                                                         @Validated PageParamRequest pageParamRequest) {
        return BaseResult.success(BasePage.restPage(articleService.getList(cid, pageParamRequest)));
    }

    /**
     * 热门列表
     */
    @ApiOperation(value = "热门列表")
    @RequestMapping(value = "/hot/list", method = RequestMethod.GET)
    public BaseResult<BasePage<ArticleResponse>> getHotList() {
        return BaseResult.success(BasePage.restPage(articleService.getHotList()));
    }

    /**
     * 轮播列表
     */
    @ApiOperation(value = "轮播列表")
    @RequestMapping(value = "/banner/list", method = RequestMethod.GET)
    public BaseResult<BasePage<Article>> getList() {
        return BaseResult.success(BasePage.restPage(articleService.getBannerList()));
    }

    /**
     * 文章分类列表
     */
    @ApiOperation(value = "文章分类列表")
    @RequestMapping(value = "/category/list", method = RequestMethod.GET)
    public BaseResult<BasePage<Category>> categoryList() {
        return BaseResult.success(BasePage.restPage(articleService.getCategoryList()));
    }

    /**
     * 查询文章详情
     * @param id Integer
     */
    @ApiOperation(value = "详情")
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    @ApiImplicitParam(name="id", value="文章ID")
    public BaseResult<ArticleResponse> info(@RequestParam(value = "id") Integer id) {
        return BaseResult.success(articleService.getVoByFront(id));
   }

    /**
     * 车队风采列表
     * @param pageParamRequest
     * @return
     */
   @ApiOperation("车队风采列表")
   @GetMapping("/list-team-style")
   public BaseResult<BasePage<ArticleResponse>> listTeamStyle(@Validated PageParamRequest pageParamRequest) {
        // 只查询车队风采的文章列表
       return BaseResult.success(BasePage.restPage(articleService.getList(CategoryConstants.CATEGORY_ID_TEAM_STYLE, pageParamRequest)));
   }

    /**
     * 健康科普列表
     * @param pageParamRequest
     * @return
     */
    @ApiOperation("健康科普列表")
    @GetMapping("/list-health")
    public BaseResult<BasePage<ArticleResponse>> listHealth(@Validated PageParamRequest pageParamRequest) {
        // 只查询车队风采的文章列表
        return BaseResult.success(BasePage.restPage(articleService.getList(CategoryConstants.CATEGORY_ID_HEALTH, pageParamRequest)));
    }
}



